package org.smile.orm.mapping.property;

import org.smile.beans.converter.BasicConverter;
import org.smile.beans.converter.ConvertException;
import org.smile.db.sql.Mapping;

/**
 * 数据有效标记的属性字段封装
 *
 * @author 胡真山
 * @Date 2016年2月25日
 */
public class LogicDeleteFlagProperty implements Mapping {
    /**
     * 启用时的值
     */
    private Object value;
    /**
     * 不启用时的值
     */
    private Object delete;
    /**
     * 字段属性
     */
    private OrmFieldProperty property;

    public LogicDeleteFlagProperty(OrmFieldProperty property) {
        this.property = property;
    }

    /**
     * 初妈化物料删除的对应值
     *
     * @param value  有效时的值
     * @param delete 无效时的值
     * @throws ConvertException
     */
    public void initFlagValue(String value, String delete) throws ConvertException {
        Class<?> fieldType = property.getFieldType();
        this.value = BasicConverter.getInstance().convert(fieldType, value);
        this.delete = BasicConverter.getInstance().convert(fieldType, delete);
    }

    public OrmFieldProperty getProperty() {
        return property;
    }

    public void setProperty(OrmFieldProperty property) {
        this.property = property;
    }

    @Override
    public String getPropertyName() {
        return property.getPropertyName();
    }

    @Override
    public String getColumnName() {
        return property.getColumnName();
    }

    @Override
    public String getPropertyExp() {
        return property.getPropertyExp();
    }

    public Object getValue() {
        return value;
    }


    public Object getDelete() {
        return delete;
    }

}
